
import 'package:baselib/utils/image_util.dart';
import 'package:baselib/utils/keyboard_util.dart';
import 'package:baselib/widgets/form_input_widget.dart';
import 'package:baselib/widgets/single_input_control_widget.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:framelib/base/base_view_model.dart';
import 'package:framelib/utils/color_util.dart';
import 'package:framelib/utils/drawable_util.dart';
import 'package:framelib/utils/px_util.dart';
import 'package:framelib/utils/string_util.dart';
import 'package:get/get.dart';

class PageWidget{

  static Widget build<T extends BaseViewModel>({bool isCreate,tag,global,controller,Function(T) builder}){
    print('TPPageUtil-->build,controller=$controller');
    return (isCreate??false)?
      GetBuilder<T>(
        init: controller,
        global: global??false,
        builder: (T controller)=>builder(controller)):
    GetBuilder<T>(
        tag: tag,
        builder: (T controller)=>builder(controller))
    ;
  }


  static PageScaffoldWidget({
    Key key,BuildContext context,
    bool isShowBgImg,String isShowBgImgPath,bool isShowBg,Color backgroundColor,Color bodyBackgroundColor,
    PreferredSizeWidget appBar,Widget drawer,DragStartBehavior drawerDragStartBehavior,
    Widget body,Widget bottomNavigationBar}){
    return KeyBoardUtil.KeyBoardOnTouchDownWidget(
        context??Get.context,
        child: Stack(
          children: [
            (!(isShowBgImg??false))?Container():Positioned(
                top: PxUtil.instance.px_0,
                left: PxUtil.instance.px_0,
                child: Container(
                  height: PxUtil.instance.screenHeight,//
                  child: ImagesUtil.loadAssetImage(
                      isShowBgImgPath,
                    width: PxUtil.instance.screenHeight,
                    fit: BoxFit.fitHeight
                  ),
                )
            ),
            (!(isShowBg??false))?Container():Positioned(
                top: PxUtil.instance.px_0,
                left: PxUtil.instance.px_0,
                right: PxUtil.instance.px_0,
                bottom: PxUtil.instance.px_0,
                child: Container(
                  width: PxUtil.instance.screenWidth,
                  height: PxUtil.instance.screenHeight,
                  decoration: BoxDecoration(
                    gradient: LinearGradient(
                      begin: Alignment.topCenter,
                      end: Alignment.bottomCenter,
                      colors: [
                        ColorUtil.instance.color_344E8E,
                        ColorUtil.instance.color_2F3660,
                      ]
                    )
                  ),
                  child: Text(''),
                )
            ),
            Scaffold(
              key: key,
              //#344E8E  #2F3660
              backgroundColor: backgroundColor??ColorUtil.instance.color_transparent,
              appBar: appBar,
              drawer: drawer,
              drawerDragStartBehavior: drawerDragStartBehavior??DragStartBehavior.start,
              bottomNavigationBar: bottomNavigationBar,
              body: Container(
                color: bodyBackgroundColor??ColorUtil.instance.color_transparent,
                child: body,
              ),
            )
          ],
        )
    );
  }
  //备注
  static buidRemarkUi(
      {String notes,
        String hitText,
        bool isShowTopTitle: true,
        bool isNecessary: false,
        bool readOnly: false,
        String remarkTitle,
        double formInputMarginBottom,
        EdgeInsetsGeometry margin,
        List<TextInputFormatter>inputFormatters,
        Function inputChanged,
        Color bgColor,
        Alignment outAlignment,
        TextAlign inputTextAlign,
        double hintFontSize,
        double fontSize,
        Color hintFontColor,
        Color fontColor,
        EdgeInsetsGeometry titleMargin,
        TextStyle titleStyle,
        TextInputType keyboardType,
        double inputHeight,
        int maxLines,
        int minLines,
        BorderRadiusGeometry borderRadius,
        Color borderColor
      }) {
    return Container(
      margin: margin ?? EdgeInsets.only(top: PxUtil.instance.px_10),
      width: PxUtil.instance.screenWidth,
      decoration: BoxDecoration(
        color: bgColor??ColorUtil.instance.color_white,
        borderRadius: borderRadius
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          // //备注信息
          // (!(isShowTopTitle ?? false))
          //     ? Container()
          //     : CommWidgetManager.buildItemTopTitleUi(
          //     title: StringUtils.remark + StringUtils.info,
          //     isShowArrow: false,
          //     arrowPath: DrawableUtils.icon_arrow_down),
          // (!(isShowTopTitle ?? false))
          //     ? Container()
          //     : CommWidgetManager.commBar(
          //     width: PxUtils.screenWidth,
          //     height: PxUtils.px_1,
          //     color: ColorUtils.color_f2f2f2),
          //备注
          Container(
            margin: EdgeInsets.only(
              left: PxUtil.instance.px_15,
              right: PxUtil.instance.px_15,
              top: PxUtil.instance.px_10,
              bottom: formInputMarginBottom??PxUtil.instance.px_12,
            ),
            child: FormInputWidget(
              title: remarkTitle??StringUtil.instance.remark,
              isNecessary: isNecessary,
              inputFormatters: inputFormatters,
                outAlignment:outAlignment,
                inputTextAlign:inputTextAlign,
              fontSize: fontSize,
              fontColor: fontColor,
              height: inputHeight,
              maxLines: maxLines,
              minLines: minLines,
              hintFontSize: hintFontSize,
              hintFontColor: hintFontColor,
              titleMargin: titleMargin,
              titleStyle: titleStyle,
              keyboardType: keyboardType,
              borderColor: borderColor,
              hintText: hitText ?? (StringUtil.instance.pleaseinput + StringUtil.instance.remark),
              readOnly: readOnly,
              defaultCont: notes ?? '',
              onChanged: (value) => inputChanged(
                value,
              ),
            ),
          ),
        ],
      ),
    );
  }

  //搜索
  static buildSearchUi({String hintSearchTxt, Function inputChanged,
    Color bgColor,
    double height,EdgeInsetsGeometry margin,TextEditingController textEditingController}) {
    return Container(
      height: height??PxUtil.instance.px_46,
      width: PxUtil.instance.screenWidth,
      decoration: BoxDecoration(
          color: bgColor??ColorUtil.instance.color_white,
          borderRadius:
          BorderRadius.all(Radius.circular(PxUtil.instance.px_22))),
      padding: EdgeInsets.only(
        left: PxUtil.instance.px_12,
        right: PxUtil.instance.px_15,
      ),
      margin: margin??EdgeInsets.only(
        // left: PxUtils.px_8,
        // right: PxUtils.px_8,
        top: PxUtil.instance.px_5,
        bottom: PxUtil.instance.px_5,
      ),
      child: Row(
        children: <Widget>[
          //搜索img
          Container(
            width: PxUtil.instance.px_18,
            height: PxUtil.instance.px_17d5,
            margin: EdgeInsets.only(right: PxUtil.instance.px_8),
            child: ImagesUtil.loadAssetImage(
                DrawableUtil.instance.icon_search_black),
          ),
          Expanded(
            child: SingleInputControlWidget(
              height: PxUtil.instance.px_46,
              underLineDefaultBorderColor: ColorUtil.instance.color_transparent,
              underLineFocusedBorderColor: ColorUtil.instance.color_transparent,
              hintText: StringUtil.instance.pleaseinput + '${hintSearchTxt ?? ''}',
              keyboardType: TextInputType.text,
              textEditingController: textEditingController,
              autofocus: false,
              onChanged: (value){
                if(inputChanged!=null)inputChanged(value,);
              },
            ),
          ),
        ],
      ),
    );
  }
}
